﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace LibNiconico.NiconicoApi.Lives.Broadcast
{
    /// <summary>
    /// 放送可能なコミュニティ情報
    /// </summary>
    public class NicoLiveBroadcastableCommunityInfo
    {
        private NicoLiveBroadcastableCommunityInfo(string communityId, string description, int communityLevel)
        {
            this.CommunityId = communityId;
            this.Description = description;
            this.CommunityLevel = communityLevel;
        }

        /// <summary>
        /// コミュニティID
        /// </summary>
        public string CommunityId { get; private set; }

        /// <summary>
        /// コミュニティ詳細
        /// </summary>
        public string Description { get; private set; }

        /// <summary>
        /// コミュニティレベル
        /// </summary>
        public int CommunityLevel { get; private set; }


        internal static NicoLiveBroadcastableCommunityInfo Parse(string communityId, string description, string levelText)
        {

            int communityLevel = 0;

            var levelMatch = Regex.Match(levelText, "[0-9]+");

            if (levelMatch.Success)
            {
                int.TryParse(levelMatch.Value,out communityLevel);
            }

            return new NicoLiveBroadcastableCommunityInfo(communityId, description, communityLevel);
        }
    }
}
